package com.hit.sys.modular.auth.controller;

import cn.hutool.core.lang.Dict;
import cn.hutool.core.map.MapUtil;
import com.hit.core.pojo.response.ResponseData;
import com.hit.core.pojo.response.SuccessResponseData;
import com.hit.sys.modular.auth.service.AuthService;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
public class SysLoginController {

    @Resource
    private AuthService authService;

    @PostMapping("/login")
    public ResponseData login(@RequestBody Dict dict) {
        String account = dict.getStr("account");
        String password = dict.getStr("pwd");

        String token = authService.login(account, password);

        Map<String, Object> map = MapUtil.newHashMap();
        map.put("token", token);
        return new SuccessResponseData(map);
    }
}
